;Copyright 2007-2010 Niko Carpenter and Tyler Spivey
;    This file is part of Linna Home Server.
;    Linna Home is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    any later version.

;    Linna Home is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with Linna Home.  If not, see http://www.gnu.org/licenses/.

#Include <utils.au3>
$User = InputBox("Username","Please enter the username to add.","")
if @Error Then Exit
if $User = "" Then
MSGBox(16,"Error","You must enter a username.")
Exit
EndIf
$Pass = InputBox("Password","Please enter a password.","","*")
if @Error Then Exit
if $Pass = "" Then
MSGBox(16,"Error","You must enter a password.")
Exit
EndIf
if StringLen($Pass) < 6 Then
if StringLen($Pass) = 1 Then
$Char = "character"
Else
$Char = "characters"
EndIf
MSGBox(0,"Warning","The password you have entered is only "&StringLen($Pass)&" "&$Char&"! This password may be cracked quite easily. This password will be accepted but it is recommended that you enter a better one.")
EndIf
if INIWrite("users.ini",$User,"pass",_dkey($Pass,"hmlin"&$pass&$User&$Pass,1,1)) Then
INIWrite("Users.ini",$User,"trust",0)
MSGBox(64,"Success","Your user information has been entered.")
Else
MSGBox(16,"Error","Cannot write to file. Is read only.")
EndIf
